package com.yyx.lgb.manager.controller;

import com.github.pagehelper.PageInfo;
import com.yyx.lgb.manager.service.SysUserService;
import com.yyx.lgb.model.dto.system.AssginRoleDto;
import com.yyx.lgb.model.dto.system.SysUserDto;
import com.yyx.lgb.model.entity.system.SysUser;
import com.yyx.lgb.model.vo.common.Result;
import com.yyx.lgb.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

/**
 * ClassName: SysUserController
 * Package: com.yyx.lgb.manager.controller
 * Description:
 *
 * @Author: yyx
 * @Create: 2025/8/1 - 16:01
 */
@RestController
@RequestMapping(value = "/admin/system/sysUser")
public class SysUserController {
    @Autowired
    private SysUserService sysUserService;

    @GetMapping(value = "/findByPage/{pageNum}/{pageSize}")
    public Result<PageInfo<SysUser>> findByPage(SysUserDto sysUserDto,
                                                @PathVariable(value = "pageNum") Integer pageNum,
                                                @PathVariable(value = "pageSize")Integer pageSize){
       PageInfo<SysUser>pageInfo= sysUserService.findByPage(sysUserDto,pageNum,pageSize);
       return Result.build(pageInfo, ResultCodeEnum.SUCCESS);
    }

    @PostMapping(value = "saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping(value = "updateSysUser")
    public Result updateSysUser(@RequestBody SysUser sysUser){
        sysUserService.updateSysUser(sysUser);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteById/{userId}")
    public Result deleteSysUser(@PathVariable(value = "userId") Long userId){
        sysUserService.deleteById(userId) ;
        return Result.build(null , ResultCodeEnum.SUCCESS);
    }
    @PostMapping("doAssign")
    public Result doAssign(@RequestBody AssginRoleDto assginRoleDto){
        sysUserService.doAssign(assginRoleDto);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

}
